package com.cmcc.waf.report.utils;

import com.cmcc.waf.report.core.exception.ErrorCode;
import com.fasterxml.jackson.annotation.JsonInclude;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;

import java.io.Serializable;



/**
 * 响应数据
 *
 * @author
 * @since 1.0.0
 */
@ApiModel(value = "响应")
public class EcloudResult<T> implements Serializable {
    private static final long serialVersionUID = 1L;
    /**
     * 编码：0表示成功，其他值表示失败
     */
    @ApiModelProperty(value = "编码：0表示成功，其他值表示失败")
    private int code = 200;
    /**
     * 消息内容
     */
    @ApiModelProperty(value = "消息内容")
    private String message = "success";
    /**
     * 响应数据
     */
    @ApiModelProperty(value = "响应数据")
    @JsonInclude(JsonInclude.Include.NON_NULL)
    private T data;

    @ApiModelProperty(value = "响应数据")
    private String productType = "Web全栈防护";

    public EcloudResult<T> ok(T data) {
        this.setData(data);
        return this;
    }

    public boolean success() {
        return code == 200 ? true : false;
    }

    public EcloudResult<T> error() {
        this.code = ErrorCode.INTERNAL_SERVER_ERROR;
        return this;
    }

    public EcloudResult<T> error(int code) {
        this.code = code;
        return this;
    }

    public EcloudResult<T> error(int code, String msg) {
        this.code = code;
        this.message = msg;
        return this;
    }

    public EcloudResult<T> error(String msg) {
        this.code = ErrorCode.INTERNAL_SERVER_ERROR;
        this.message = msg;
        return this;
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String msg) {
        this.message = msg;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    public String getProductType() {
        return productType;
    }

    public void setProductType(String productType) {
        this.productType = productType;
    }
}
